import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/6 18:03
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {3,1,5,6,4,2};
        solution.maxSumMinProduct(nums);
    }
    public int maxSumMinProduct(int[] nums) {
        int MOD = 1_000_000_007;
        int n = nums.length;
        long[] subSum = new long[n];
        for (int i = 0; i < n; i++) {
            int min = nums[i], left = i - 1 , right = i + 1;
            long sum = min;
            while (left >= 0 && nums[left] >= min) {
                sum += nums[left];
                left--;
            }
            while (right < n && nums[right] >= min) {
                sum += nums[right];
                right++;
            }
            subSum[i] = sum;
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            if (nums[i] * subSum[i] > ans) {
                ans = nums[i] * subSum[i];
            }
        }
        return (int) ans % MOD;
    }
}
